﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;
public partial class Login : System.Web.UI.Page
{
    MaHoaMK_BLL MaHoa = new MaHoaMK_BLL();
    DataTable dt = new DataTable();
    KhachHang_BLL KH = new KhachHang_BLL();
    protected void Page_Load(object sender, EventArgs e)
    {
        txtTenDN.Focus();
    }
    protected void btnTuChoi_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Default.aspx");
    }
    protected void btnDangNhap_Click(object sender, EventArgs e)
    {        
        string MatKhau = MaHoa.GetMD5(txtMatKhau.Text.Trim() + "");
        DateTime DNLanCuoi = new DateTime();
        DNLanCuoi = DateTime.Now;
        int reVal = KH.KhachHang_DangNhap(txtTenDN.Text.TrimEnd() + "", MatKhau,DNLanCuoi,1);
        if (reVal > 0)
        {
            Session["Khach"] = txtTenDN.Text;            
            if (Session["DuongDan"] != null)
            {
                Response.Redirect(Session["DuongDan"].ToString());
            }
            else Response.Redirect("~/Default.aspx");
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Login fail! ');", true);
        }
    }
}
